<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/18
 * Time: 10:53
 */
namespace app\admin\controller;
use  think\Db;
class Intelligence extends Base {
    public function index(){
        if(request()->isAjax ()){
            $params = input('param.');
            $where = [];
            //手机号
            if(isset($params['key']) && $params['key'] != '')
            {
                $where['s_name|s_phone'] = ['like', "%" . $params['key'] . "%"];
            }
            if(isset($params['s_status']) && $params['s_status'] != '')
            {
                $where['s_status'] = $params['s_status'];
            }else{
                $where['s_status'] = array('IN',array(2,3,1));
            }

            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('shops')->where($where)->count();// 获取总条数
            $lists = Db::name('shops')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('s_id desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        if(session('?s_id')){
            session('s_id',null);
        }

        if(session('?tu_id')){
            session('tu_id',null);
        }
        return $this->fetch();
    }
    //详情
    public function detail(){
        $id= input('param.id');
        $info = Db::table('up_shops')->where('s_id',$id)->find();
        if($info['s_status']==1){
            $info['s_status_name']='审核中';
        }
        if($info['s_status']==2){
            $info['s_status_name']='通过';
        }
        if($info['s_status']==3){
            $info['s_status_name']='拒绝';
        }
        $this->assign('info',$info);
        return $this->fetch();
    }
    //审核
    public function examine(){
        if(request()->isPost()){
            $id = input('param.id');
            $data['s_status'] = input('param.s_status');
            $data['s_reason'] = input('param.s_reason');
            $data['s_sh_time'] = date('Y-m-d H:i:s',time());
            $res = Db::table('up_shops')->where('s_id', $id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '操作成功']);
            }else{
                return json(['code' => 100, 'msg' => '操作失败']);
            }
        }
        $id= input('param.id');
        $info = Db::table('up_shops')->where('s_id',$id)->find();
        $this->assign('info',$info);
        return $this->fetch();
    }
}